/**
 * 作者：陈文斌 on 2019/1/5.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/main_scoped_model.dart';

class ClientManagerTabsSection extends StatefulWidget {
  final TabController tabController;
  final List<String> tabTitles;
  final Function changeListStyle;

  @override
  ClientManagerTabsSection({
    Key key,
    this.tabController,
    this.tabTitles,
    this.changeListStyle,
  }) : super(key: key);

  State<StatefulWidget> createState() => _ClientManagerTabsSectionState();
}

class _ClientManagerTabsSectionState extends State<ClientManagerTabsSection> {
  final String _arrangementImage = 'images/ic_list_arrangement.png';
  final String _leftRightImage = 'images/ic_list_left_right.png';
  @override
  void initState() {
    super.initState();
    final clientManagerScopedModel = MainModel().of(context);
    clientManagerScopedModel.changeClientManagerListStyle(true);
  }

  @override
  Widget build(BuildContext context) {
    final clientManagerScopedModel = MainModel().of(context);
    return Container(
      height: 40,
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Expanded(
            child: TabBar(
              controller: widget.tabController,
              labelColor: AppColors.MainColor,
              indicatorColor: AppColors.MainColor,
              unselectedLabelColor: AppColors.TextColor,
              indicatorSize: TabBarIndicatorSize.label,
              tabs: widget.tabTitles.map((String title) {
                return Tab(
                  text: title ?? '错误',
                );
              }).toList(),
            ),
          ),
          Container(
            width: 1,
            height: 20,
            color: AppColors.LineColor,
          ),
          Container(
            width: 50,
            height: 40,
            alignment: Alignment.center,
            child: InkWell(
              onTap: () {
                if (widget.changeListStyle != null) {
                  widget.changeListStyle();
                }
                setState(() {});
              },
              child: Image.asset(
                clientManagerScopedModel.clientManagerListIsArrangement ? _arrangementImage : _leftRightImage,
                width: 20,
                height: 20,
              ),
            ),
          )
        ],
      ),
    );
  }
}
